package www.hn.com.shang.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import www.hn.com.shang.bean.*;
import www.hn.com.shang.dao.ChengshiMapper;
import www.hn.com.shang.dao.JiashiMapper;
import www.hn.com.shang.dao.WeizhangMapper;
import www.hn.com.shang.service.JiashiService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * hanni
 * 2019/1/20 0020
 * 14:46
 */
@Service
public class JiashiServiceImpl implements JiashiService {

    @Resource
    private JiashiMapper jiashiMapper;

    @Resource
    private ChengshiMapper chengshiMapper;

    @Resource
    private WeizhangMapper weizhangMapper;


    @Override
    public Map<String, Object> selectObjects(Integer page, Integer rows, JiashiExample jiashiExample) {
        Map<String,Object> map = new HashMap<>();
        PageHelper.startPage(page,rows);
        List<Map<String,Object>> list = jiashiMapper.selectByExample(jiashiExample);
        PageInfo<Map<String,Object>> pageInfo= new PageInfo<>(list);
        map.put("total",pageInfo.getTotal());
        map.put("rows",pageInfo.getList());

        return map;
    }

    @Override
    public void insert(Jiashi jiashi) throws Exception {

        jiashiMapper.insert(jiashi);

    }

    @Override
    public void update(Jiashi jiashi) throws Exception {
        jiashiMapper.updateByPrimaryKey(jiashi);

    }

    @Override
    public List<Chengshi> getCheng(Integer pid) {

        ChengshiExample chengshiExample = new ChengshiExample();
        chengshiExample.createCriteria().andPidEqualTo(pid);
        List<Chengshi> list = chengshiMapper.selectByExample(chengshiExample);

        return list;
    }

    @Override
    public List<Weizhang> getWeizhang(Integer jid) {

        WeizhangExample weizhangExample = new WeizhangExample();
        weizhangExample.createCriteria().andJidEqualTo(jid);
        List<Weizhang> list = weizhangMapper.selectByExample(weizhangExample);

        return list;
    }
}
